<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <link rel="stylesheet" href="css/bootstrap.css">
    <script src="js/jquery.js" type="text/javascript"></script>
    <script src="js/bootstrap.js" type="text/javascript"></script>
    <script src="js/jsrender.js" type="text/javascript"></script>
    <script src="js/common.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function(){
            if(localStorage.getItem("token")==null){
                window.location.href="login.html"
            }
            $.ajax({
                url: GC.bctx + localStorage.getItem("account") ,
                type: "GET",
                headers: {"Authorization": localStorage.getItem("token")},
                success:function(r){
                    if(r.successed){
                        $("#userId").val(r.data.userId)
                        $("#userAccount").val(r.data.userAccount)
                        $("#userPassword").val(r.data.userPassword)
                        $("#userTelephone").val(r.data.userTelephone)
                        $("#userPosition").val(r.data.userPosition)
                    }else{
                        alert(r.message)
                    }
                }
            })
            $("form").submit(function(){
                if(localStorage.getItem("account")!=$("#userAccount").val()&&localStorage.getItem("position")==0)
                {
                    alert("您的权限不足")
                    return
                }
                if($("#userPassword").val()==$("#userNewPassword").val()) {
                    $.ajax({
                        url: GC.bctx + "/update/" + localStorage.getItem("account"),
                        type: "PUT",
                        data: $("form").serialize(),
                        headers: {"Authorization": localStorage.getItem("token")},
                        success: function (r) {
                            if (r.successed) {
                                //修改成功，转向显示所有部门页面
                                alert(r.message)
                                window.location.href = "managers.html"
                            } else {
                                //修改失败，显示失败信息
                                alert(r.message)
                            }

                        }
                    })
                }else{
                    alert("两次密码输入不一致")
                }
                return false
            })
        })
    </script>
</head>
<body>
<div class="container-fluid">
    <h1>用户信息</h1>
    <hr/>
    新密码:
    <input id="userNewPassword" name="userNewPassword" type="password"/>
    <form>
        <table>
            <tr class="d-none">
                <td >编号：</td>
                <td><input id="userId" name="userId" type="text"/></td>
                <td><span class="c-r">*</span></td>
            </tr>
            <tr class="d-none">
                <td>账号：</td>
                <td><input id="userAccount" name="userAccount" readonly="true" type="text"/></td>
                <td><span class="c-r">*</span></td>
            </tr >
            <tr>
                <td >再次确认密码：</td>
                <td><input id="userPassword" name="userPassword" type="password"/></td>
                <td><span class="c-r">*</span></td>
            </tr>
            <tr class="d-none">
                <td>电话：</td>
                <td><input id="userTelephone" name="userTelephone" type="text"/></td>
                <td><span class="c-r">*</span></td>
            </tr>
            <tr class="d-none">
                <td>职位权限：</td>
                <td><select id="userPosition" name="userPosition" readonly="true" disabled="disabled">
                    <option value="0">普通员工</option>
                    <option value="1">管理人员</option>
                </select></td>
                <td></td>
            </tr>
            <tr>
                <td colspan="3" class="text-center">
                    <input type="submit" value="修改"/>
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>